package com.tao.service;

import com.tao.mapper.UserMapper;
import com.tao.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig(cacheNames = "UserName")
public class UserServiceImpl implements UserService {
    @Autowired
    private    UserMapper userMapper;

    @Override
    @CacheEvict(key = "9527")
    public int deleteByPrimaryKey(Integer id) {

        System.out.println("删除了id="+id);
        return userMapper.deleteByPrimaryKey(id);
    }


    @Override
    public User selectByPrimaryKey(Integer id) {
        System.out.println("数据库 查询了 数据 id:"+id);
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    @CacheEvict(key = "9527")
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    @Cacheable(key = "9527")
    public List<User> selectAll() {

        System.out.println("查询了全部数据");
        return userMapper.selectAll();
    }

    @Override
    public User selectByname(String username) {

        System.out.println("数据库查询了数据 name=:"+username);
        return userMapper.selectByname(username);
    }

    @Override
    @CacheEvict(key = "9527")
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }


}
